package com.future.hedongjun.mine.order;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Button;
import android.widget.EditText;

import com.future.baselib.activity.BaseActivity;
import com.future.hedongjun.R;
import com.future.hedongjun.mall.bean.OrderDetail;
import com.future.hedongjun.mine.adapter.OrderEvaluateAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OrderEvaluateActivity extends BaseActivity {

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.bottom_btn)
    Button bottomBtn;
    private OrderDetail data;
    private OrderEvaluateAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_evaluate);
        ButterKnife.bind(this);
        setTitle("评价");
        bottomBtn.setText("立即评价");
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new OrderEvaluateAdapter(data.goodsBeanList);
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        super.getBundleExtras(extras);
        data = (OrderDetail) extras.getSerializable("data");
    }

    @OnClick(R.id.bottom_btn)
    public void onViewClicked() {
        List<String> contents = new ArrayList<>();
        for (int i = 0; i < data.goodsBeanList.size(); i++) {
            EditText etContent = (EditText) adapter.getViewByPosition(recyclerView, i, R.id.et_evaluate_content);
            if (etContent != null) {
                contents.add(etContent.getText().toString().trim());
            }
        }

        StringBuilder all = new StringBuilder();
        for (String content : contents) {
            all.append(content).append(" ");
        }
        toast(all.toString());
    }
}
